#include "collisionHandle.h"
#include <stdio.h>
#include <iostream>
using namespace std;

	collisionHandle::collisionHandle()
	{
		for(int i=0; i<=255;i++)
		{

			boxes[i].active = false;
		}
	}
	int collisionHandle::addBox(int x, int y, int h, int w)
	{
		for(int i=0; i<255;i++)
		{
			if(boxes[i].active!=true){
			boxes[i].x = x;
			boxes[i].y = y;
			boxes[i].h = h;
			boxes[i].w = w;
			boxes[i].active = true;
			return i;
			//cout << "box found" << endl;
			}
		}
	}
	void collisionHandle::removeBox(int id)
	{
		boxes[id].active=false;
	}
	bool collisionHandle::checkBox(float x, float y, float x2, float y2)
	{
		float xbuf;
		float ybuf;
		bool flag = false;
		//process boxes incase they are upsidedown/backward
		if(x2<x)
		{
			xbuf = x;
			x = x2;
			x2 = xbuf;
		}
		if(y2<y)
		{
			ybuf = y;
			y = y2;
			y2 = ybuf;
		}
		
		for(int i=0; i<255; i++)//i<=counter is obsolete. use i<=maxboxes.
		{
			if(boxes[i].active)
			{
				if(x2 > boxes[i].x && x < boxes[i].x + boxes[i].w && y2 > boxes[i].y && y < boxes[i].y + boxes[i].h)
				{
				flag=true;
				break;
				}
				else
				{
				flag=false;
				}
			}
		}
		return flag;
	}

